//
//  GLSLViewController_Shader.swift
//  ZSceneDemo
//
//  Created by 张鑫 on 2020/9/14.
//  Copyright © 2020 www.lionaitech.com. All rights reserved.
//

import UIKit

class MetalSLViewController {

    
    

    func shaderModifiers() {
        
        /**
         先写一个顶点着色器程序,写个简单点的
         _geometry.position.z = _geometry.position.x * 3;
         
         在写个灯光的着色器程序
         _lightingContribution.diffuse = vec3(0.1,0.3,0.4);
         
         直接使用无效，使用方法：
         let mapGeometry = "_geometry.position.z = _geometry.position.x * 3;"
         let mapLight = "_lightingContribution.diffuse = vec3(0.1,0.3,0.4);"
         */
        
        let mapGeometry = try? String(contentsOf: Bundle.main.url(forResource: "wave", withExtension: "shader")!,encoding: .utf8)
        let mapLight = try? String(contentsOf: Bundle.main.url(forResource: "mapLighting", withExtension: "shader")!, encoding: .utf8)
        
        let node = SCNNode(geometry: SCNPlane(width: 10, height: 10))
        node.geometry?.shaderModifiers = [SCNShaderModifierEntryPoint.geometry : mapGeometry!,
                                          SCNShaderModifierEntryPoint.fragment : "",
                                          SCNShaderModifierEntryPoint.lightingModel : mapLight!,
                                          SCNShaderModifierEntryPoint.surface : "",]
        
//        sceneView?.scene?.rootNode.addChildNode(node)
        /**
         1. 顶点(vertex)   (SCNShaderModifierEntryPointGeometry)
         2. 表面(surface)  (SCNShaderModifierEntryPointSurface)
         3. 灯光(lighting) (SCNShaderModifierEntryPointLightingModel)
         4. 片段(fragment) (SCNShaderModifierEntryPointFragment)
         */
    }

}
